{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>\n",
       "@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
       "@import url('http://fonts.googleapis.com/css?family=Vollkorn');\n",
       "@import url('http://fonts.googleapis.com/css?family=Arimo');\n",
       "\n",
       "    div.cell{\n",
       "        width: 850px;\n",
       "        margin-left: 0% !important;\n",
       "        margin-right: auto;\n",
       "    }\n",
       "    div.text_cell code {\n",
       "        background: transparent;\n",
       "        color: #000000;\n",
       "        font-weight: 600;\n",
       "        font-size: 11pt;\n",
       "        font-style: bold;\n",
       "        font-family:  'Source Code Pro', Consolas, monocco, monospace;\n",
       "   }\n",
       "    h1 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "\t}\n",
       "\t\n",
       "    div.input_area {\n",
       "        background: #F6F6F9;\n",
       "        border: 1px solid #586e75;\n",
       "    }\n",
       "\n",
       "    .text_cell_render h1 {\n",
       "        font-weight: 200;\n",
       "        font-size: 30pt;\n",
       "        line-height: 100%;\n",
       "        color:#c76c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 1em;\n",
       "        display: block;\n",
       "        white-space: wrap;\n",
       "    } \n",
       "    h2 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h2 {\n",
       "        font-weight: 200;\n",
       "        font-size: 16pt;\n",
       "        font-style: italic;\n",
       "        line-height: 100%;\n",
       "        color:#c76c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 1.5em;\n",
       "        display: inline;\n",
       "        white-space: wrap;\n",
       "    } \n",
       "    h3 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h3 {\n",
       "        font-weight: 200;\n",
       "        font-size: 14pt;\n",
       "        line-height: 100%;\n",
       "        color:#d77c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 2em;\n",
       "        display: block;\n",
       "        white-space: nowrap;\n",
       "    }\n",
       "    h4 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h4 {\n",
       "        font-weight: 100;\n",
       "        font-size: 14pt;\n",
       "        color:#d77c0c;\n",
       "        margin-bottom: 0.5em;\n",
       "        margin-top: 0.5em;\n",
       "        display: block;\n",
       "        white-space: nowrap;\n",
       "    }\n",
       "    h5 {\n",
       "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "    }\n",
       "    .text_cell_render h5 {\n",
       "        font-weight: 200;\n",
       "        font-style: normal;\n",
       "        color: #1d3b84;\n",
       "        font-size: 16pt;\n",
       "        margin-bottom: 0em;\n",
       "        margin-top: 0.5em;\n",
       "        display: block;\n",
       "        white-space: nowrap;\n",
       "    }\n",
       "    div.text_cell_render{\n",
       "        font-family: 'Arimo',verdana,arial,sans-serif;\n",
       "        line-height: 125%;\n",
       "        font-size: 120%;\n",
       "        width:740px;\n",
       "        margin-left:auto;\n",
       "        margin-right:auto;\n",
       "        text-align:justify;\n",
       "        text-justify:inter-word;\n",
       "    }\n",
       "    div.output_subarea.output_text.output_pyout {\n",
       "        overflow-x: auto;\n",
       "        overflow-y: scroll;\n",
       "        max-height: 50000px;\n",
       "    }\n",
       "    div.output_subarea.output_stream.output_stdout.output_text {\n",
       "        overflow-x: auto;\n",
       "        overflow-y: scroll;\n",
       "        max-height: 50000px;\n",
       "    }\n",
       "    div.output_wrapper{\n",
       "        margin-top:0.2em;\n",
       "        margin-bottom:0.2em;\n",
       "}\n",
       "\n",
       "    code{\n",
       "      font-size: 70%;\n",
       "    }\n",
       "    .rendered_html code{\n",
       "    background-color: transparent;\n",
       "    }\n",
       "    ul{\n",
       "        margin: 2em;\n",
       "    }\n",
       "    ul li{\n",
       "        padding-left: 0.5em; \n",
       "        margin-bottom: 0.5em; \n",
       "        margin-top: 0.5em; \n",
       "    }\n",
       "    ul li li{\n",
       "        padding-left: 0.2em; \n",
       "        margin-bottom: 0.2em; \n",
       "        margin-top: 0.2em; \n",
       "    }\n",
       "    ol{\n",
       "        margin: 2em;\n",
       "    }\n",
       "    ol li{\n",
       "        padding-left: 0.5em; \n",
       "        margin-bottom: 0.5em; \n",
       "        margin-top: 0.5em; \n",
       "    }\n",
       "    ul li{\n",
       "        padding-left: 0.5em; \n",
       "        margin-bottom: 0.5em; \n",
       "        margin-top: 0.2em; \n",
       "    }\n",
       "    a:link{\n",
       "       font-weight: bold;\n",
       "       color:#447adb;\n",
       "    }\n",
       "    a:visited{\n",
       "       font-weight: bold;\n",
       "       color: #1d3b84;\n",
       "    }\n",
       "    a:hover{\n",
       "       font-weight: bold;\n",
       "       color: #1d3b84;\n",
       "    }\n",
       "    a:focus{\n",
       "       font-weight: bold;\n",
       "       color:#447adb;\n",
       "    }\n",
       "    a:active{\n",
       "       font-weight: bold;\n",
       "       color:#447adb;\n",
       "    }\n",
       "    .rendered_html :link {\n",
       "       text-decoration: underline; \n",
       "    }\n",
       "    .rendered_html :hover {\n",
       "       text-decoration: none; \n",
       "    }\n",
       "    .rendered_html :visited {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .rendered_html :focus {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .rendered_html :active {\n",
       "      text-decoration: none;\n",
       "    }\n",
       "    .warning{\n",
       "        color: rgb( 240, 20, 20 )\n",
       "    } \n",
       "    hr {\n",
       "      color: #f3f3f3;\n",
       "      background-color: #f3f3f3;\n",
       "      height: 1px;\n",
       "    }\n",
       "    blockquote{\n",
       "      display:block;\n",
       "      background: #fcfcfc;\n",
       "      border-left: 5px solid #c76c0c;\n",
       "      font-family: 'Open sans',verdana,arial,sans-serif;\n",
       "      width:680px;\n",
       "      padding: 10px 10px 10px 10px;\n",
       "      text-align:justify;\n",
       "      text-justify:inter-word;\n",
       "      }\n",
       "      blockquote p {\n",
       "        margin-bottom: 0;\n",
       "        line-height: 125%;\n",
       "        font-size: 100%;\n",
       "      }\n",
       "</style>\n",
       "<script>\n",
       "    MathJax.Hub.Config({\n",
       "                        TeX: {\n",
       "                           extensions: [\"AMSmath.js\"]\n",
       "                           },\n",
       "                tex2jax: {\n",
       "                    inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
       "                    displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
       "                },\n",
       "                displayAlign: 'center', // Change this to 'center' to center equations.\n",
       "                \"HTML-CSS\": {\n",
       "                    scale:85,\n",
       "                    styles: {'.MathJax_Display': {\"margin\": 4}}\n",
       "                }\n",
       "        });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from __future__ import division, print_function\n",
    "%matplotlib inline\n",
    "import sys\n",
    "sys.path.insert(0,'..') # allow us to format the book\n",
    "sys.path.insert(0,'../code') \n",
    "# use same formatting as rest of book so that the plots are\n",
    "# consistant with that look and feel.\n",
    "import book_format\n",
    "book_format.load_style(directory='..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaIAAAEWCAYAAAAkUJMMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtUlOedB/DvzHC/CsLAAMP9fhcQFfGSBElIjLUbNZet\nrTa7adwmG5PN2ZSsbZLVJG3dYxtTNWmao0nabk36R9ImxKj1BoIRROQi90EuwgwXlZtcZ979w8qG\nOg4YYR5gvp9zPCc8PM/M75HId973fd7nlUmSJIGIiEgQuegCiIjIsjGIiIhIKAYREREJxSAiIiKh\nGERERCQUg4iIiIRiEBERkVATBtGpU6ewZs0a+Pn5QS6X44MPPpjwRcvKyrBixQo4ODjAz88P27dv\nn5JiiYho7pkwiPr7+xEfH4+33noL9vb2kMlkJvv39PRg1apVUKlUKCoqwltvvYWdO3di165dU1Y0\nERHNHbI72VnB2dkZe/bswfe///3b9tm3bx+ys7Oh0+lga2sLAHj99dexb98+tLS03H3FREQ0p0z5\nNaKCggIsW7ZsLIQAIDMzE62trWhsbJzqtyMiolluyoNIq9XCy8trXNvNr7Va7VS/HRERzXJWU/2C\nE11D+qbu7u6pfnsiIpphXF1dTX5/yo+IvL29bzny0el0Y98jIiL6pikPoiVLliA3NxdDQ0NjbUeO\nHIGvry8CAgKm+u2IiGiWm/DUXH9/P2prawEABoMBjY2NKCkpwfz586FWq5GdnY3CwkIcPXoUAPDE\nE0/gtddew6ZNm7Bt2zZUV1fjF7/4BV599VWT7zPRodtcUlRUBABISUkRXIn5ce6WN3dLnTdg2XO/\nk0svEx4RFRYWIikpCUlJSRgcHMQrr7yCpKQkvPLKKwBuLEDQaDRj/V1cXHDkyBG0trYiJSUFzz77\nLF588UU8//zz32IqREQ01014RLRy5UoYDIbbfn///v23tMXGxuLkyZN3VxkREVkE7jVHRERCMYiI\niEgoBhEREQnFICIiIqEYREREJBSDiIiIhGIQERGRUAwiIiISikFERERCMYiIiEgoBhEREQnFICIi\nIqEYREREJBSDiIiIhGIQERGRUAwiIiISikFERERCMYiIiEgoBhEREQnFICIiIqEYREREJBSDiIiI\nhGIQERGRUAwiIiISikFERERCMYiIiEgoBhEREQnFICIiIqEYREREJBSDiIiIhGIQERGRUAwiIiIS\nikFERERCMYiIiEgoBhEREQnFICIiIqEYREREJNSkgmjv3r0ICgqCvb09UlJSkJeXZ7J/Tk4OFi9e\nDBcXF3h6emLt2rWora2dkoKJiGhumTCIDh48iK1bt2Lbtm0oKSlBWloasrKy0NzcbLR/XV0d1q5d\ni5UrV6KkpARHjx7F4OAgHnzwwSkvnoiIZr8Jg2jXrl3YvHkznnzySURERGD37t1QqVTYt2+f0f4l\nJSUwGAx48803ERwcjISEBLz00kuor6/HlStXpnwCREQ0u5kMouHhYRQXFyMzM3Nce2ZmJvLz842O\nWbp0KZycnPDee+9Br9ejt7cXBw4cQGpqKtzd3aeuciIimhNMBlFnZyf0ej28vLzGtSuVSmi1WqNj\nVCoVcnJysG3bNtjZ2WHevHmoqKjAX//616mrmoiI5gyrqX5BjUaDtWvXYvPmzXjiiSfQ09ODn/3s\nZ9iwYQOOHTsGmUxmdFxRUdFUlzLjWeKcb+LcLY+lzhuwzLmHhYVNuq/JIPLw8IBCoYBOpxvXrtPp\noFKpjI559913oVar8Ytf/GKs7fe//z3UajUKCgqQlpY26eKIiGjuMxlENjY2SE5OxuHDh/HII4+M\ntR85cgTr1683OkaSJMjl48/43fzaYDDc9r1SUlImXfRsd/PTkSXN+SbO3fLmbqnzBix77t3d3ZPu\nO+GquRdeeAEHDhzA+++/j8rKSjz33HPQarV4+umnAQDZ2dnIyMgY679mzRoUFxdj+/btqK2tRXFx\nMTZv3gx/f38kJyd/i+kQEdFcNuE1og0bNqCrqws7duxAW1sb4uLikJOTA7VaDQDQarXQaDRj/dPT\n03Hw4EH8/Oc/xy9/+Us4ODhgyZIlOHToEOzt7advJkRENCtNarHCli1bsGXLFqPf279//y1t69at\nw7p16+6uMiIisgjca46IiIRiEBERkVAMIiIiEopBREREQjGIiIhIKAYREREJxSAiIiKhGERERCQU\ng4iIiIRiEBERkVAMIiIiEopBREREQjGIiIhIKAYREREJxSAiIiKhGERERCQUg4iIiIRiEBERkVAM\nIiIiEopBREREQjGIiIhIKAYREREJxSAiIiKhGERERCQUg4iIiIRiEBERkVAMIiIiEopBREREQjGI\niIhIKAYREREJxSAiIiKhGERERCQUg4iIiIRiEBERkVAMIiIiEopBREREQjGIiIhIqEkF0d69exEU\nFAR7e3ukpKQgLy9vwjG//vWvERkZCTs7O/j4+CA7O/uuiyUiornHaqIOBw8exNatW7Fv3z6kp6dj\nz549yMrKwsWLF6FWq42OeeGFF/DFF1/gf/7nfxAXF4fu7m60tbVNefFERDT7TRhEu3btwubNm/Hk\nk08CAHbv3o1D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mnRokWiyzCLt956S/L29pYOHjwolZeXSx999JHk7u4uvf/++ybHCQuirVu3Sj4+PuN+OVmijIyM\nW86pzjX79++XZDKZZGVlNfZHJpNJcrlcsra2loaHh0WXaFb33HOP9G//9m+iy5h2AQEB0r/+67+O\na/vwww8lR0dHQRWZn06nk2xsbKTf/e53oksxC6VSKe3evXtc244dO6TQ0FCT44Q8Kvy5557DJ598\nguPHjyM8PFxECTOGXq+HwWAQXca0+u53v4vU1NSxryVJwubNmxEeHo6XX34Z1taW83TewcFBVFZW\n4t577xVdyrRbunQpqqqqxrXV1NQgMDBQTEECHDhwAHZ2dnj88cdFl2IWkiRBLh+/9EAul094Tdjs\nQfTjH/8Yv//97/Hpp5/C1dV1bINUZ2dnODo6mrscs/rJT36C1atXw8/PD729vfjjH/+IkydP4tCh\nQ6JLm1Y375v6JgcHB7i5uSE6OlpQVebx4osvYs2aNVCr1Whvb8f27dsxMDCAH/zgB6JLm3bPP/88\n0tLS8MYbb2DDhg04f/483n77bbz55puiSzMLSZLwu9/9Do899hgcHBxEl2MWa9euxc9//nMEBQUh\nOjoa58+fx69+9auJ/3+frkO027l5SkYmk43789prr5m7FLPbtGmTFBAQINna2kpKpVJatWqVdPjw\nYdFlCWEpixUee+wxycfHR7KxsZF8fX2ldevWSZWVlaLLMpsvvvhCSkhIkOzs7KSIiAjp7bffFl2S\n2Rw7dkySy+Vz/hrwN/X19Un/8R//IQUGBkr29vZScHCw9F//9V/S0NCQyXHc4oeIiIQSfh8RERFZ\nNgYREREJxSAiIiKhGERERCQUg4iIiIRiEBERkVAMIiIiEopBREREQjGIiIhIqP8DiW6VK9nFPOgA\nAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x8474eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from gif_animate import animate\n",
    "from stats import gaussian\n",
    "import matplotlib.pylab as pylab\n",
    "from matplotlib import animation\n",
    "import matplotlib\n",
    "\n",
    "def plt_g (mu, variance):\n",
    "    xs = np.arange(2,8,0.05)\n",
    "    ys = [gaussian (x, mu, variance) for x in xs]\n",
    "    plt.plot (xs, ys)\n",
    "    plt.ylim((0,1))\n",
    "\n",
    "\n",
    "mu = 2\n",
    "sigma = 0.6\n",
    "def ganimate(frame):\n",
    "    global mu, sigma\n",
    "    if frame < 25:\n",
    "        mu += .2\n",
    "    elif frame == 25:\n",
    "        mu = 5\n",
    "    elif frame < 37:\n",
    "        sigma -= 0.05\n",
    "    else:\n",
    "        sigma += 0.05\n",
    "\n",
    "    plt.cla()\n",
    "    plt_g(mu,sigma)\n",
    "\n",
    "animate('04_gaussian_animate.gif', ganimate, \n",
    "        frames=80, interval=50, figsize=(6,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src='04_gaussian_animate.gif'>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
